(function($){	
	

	$.fn.fadeInOut=function(options){	
	
		var settings=$.extend({	
			nextControl: '#nextButton',	
			nextLabel: '',
			prevControl: '#prevButton',	
			prevLabel: '',
			pageControl: '.pageControl',	
		    delay: 5000,
			runTime:200,
		}, options || {});		
		
		return this.each(function(){
			settings.list=$(this).find('li');
			
			settings.pageControlDiv='<div class="'+settings.pageControl.substr(1)+'"></div>';
			
			$(this).after(settings.pageControlDiv);
			$(this).after('<a href="#" id="'+settings.nextControl.substr(1)+'">'+settings.nextLabel+'</a>');
			$(this).after('<a href="#" id="'+settings.prevControl.substr(1)+'">'+settings.prevLabel+'</a>');
			
			settings.current=0;
			
			settings.list.each(function(n){$(this).data('index',n); if(n==0){ $(settings.pageControl).append('<a href="#" class="active">'+n+'</a>');}else{$(settings.pageControl).append('<a href="#">'+n+'</a>');} });
			
			
			
			$(settings.nextControl).click(function(e){
					fadeio( (settings.current+1) % settings.list.length);e.preventDefault();
			});
			$(settings.prevControl).click(function(e){
					fadeio( (settings.current-1+settings.list.length) % settings.list.length);
					e.preventDefault();
			});
			
			$(settings.pageControl).find('a').click(function(event){fadeio($(this).text());event.preventDefault();});		
			
			function fadeio(index){
				clearInterval(settings.tick);	
				settings.list.stop(true, true);		
				settings.list.each(function(){
						if($(this).data('index')==settings.current){$(this).fadeOut(settings.runTime);}else{$(this).hide()};
					});
				settings.list.eq(index).fadeIn(settings.runTime);
				settings.current=index;	
				$(settings.pageControl).find('a').eq(index).siblings().removeClass('active').end().addClass('active');
				settings.tick=window.setInterval(function(){ $(settings.nextControl).triggerHandler('click');}, settings.delay);	
			}
			
			settings.tick=window.setInterval(function(){ $(settings.nextControl).triggerHandler('click');}, settings.delay);
		
		});
		
	}
	

})(jQuery);


